home *** CD-ROM | disk | FTP | other *** search
- RAN(3I) Last changed: 4-13-99
-
-
- NNAAMMEE
- __rraannff, RRAANNFF, RRAANNGGEETT, RRAANNSSEETT - Computes pseudo-random numbers
-
- SSYYNNOOPPSSIISS
- C/C++:
-
- ##iinncclluuddee <<iinnttrriinnssiiccss..hh>>
- ddoouubbllee __rraannff((vvooiidd));;
-
- Fortran:
-
- RRAANNFF(())
-
- RRAANNGGEETT (([II==]_i))
-
- RRAANNSSEETT (([KK==]_k))
-
- Fortran on UNICOS/mk systems only:
-
- RRAANNSSEETT (([KK==]_k [,, [JJ==]_j]))
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- C/C++: UNICOS and UNICOS/mk systems
-
- Fortran: UNICOS, UNICOS/mk, IRIX systems
-
- Cray C/C++, CF90, MIPSpro 7 Fortran 90
-
- SSTTAANNDDAARRDDSS
- C/C++ extension
-
- Fortran extension
-
- DDEESSCCRRIIPPTTIIOONN
- The __rraannff and RRAANNDD functions return a pseudo-random floating-point
- number in the range of 0.0 < _x < 1.0.
-
- The RRAANNGGEETT intrinsic procedure returns a seed from the random number
- seed table.
-
- The RRAANNSSEETT function establishes a seed in the random number seed
- table.
-
- NNOOTTEESS
- CC//CC++++
- Because __rraannff is an intrinsic function, no externally visible library
- function is available for it.
-
- FFoorrttrraann
- RRAANNFF obtains the first or next in a series of pseudo-random numbers.
- Parenthesis are required, that is: _v_a_r == RRAANNFF(()). If an argument is
- supplied, it is ignored.
-
- The RRAANNGGEETT intrinsic function obtains a seed. It can be called as a
- function or a subroutine; it is recommended that this routine be used
- as a function because it is not considered intrinsic when called as a
- subroutine. RRAANNGGEETT has an optional integer argument. If present, the
- argument is set to the seed. The argument for RRAANNGGEETT is as follows:
-
- _i An integer of default kind (KKIINNDD==88). If present, RRAANNGGEETT returns
- the seed in _i.
-
- On UNICOS and UNICOS/mk systems, the RRAANNSSEETT intrinsic function
- establishes a seed by using the lower 48 bits of the argument. The
- result type is typeless. If no argument or a zero argument is
- supplied, the seed is reset to an initial default value. When the
- seed of the random number generator is reset, RRAANNSSEETT does not store
- the supplied argument as the first value in the buffer of the random
- number seeds. If an argument is supplied, the lower 48 bits are used
- as the random-number seed. The rightmost bit is always set to 1.
-
- The RRAANNSSEETT arguments are as follows:
-
- _k An optional integer, real, or Boolean argument of default kind
- (KKIINNDD==88) The range of argument _k is |_k| < _i_n_f, where _i_n_f is as
- follows:
- 2450
- * On UNICOS systems, infinity is approximately 10 .
- 308
- * On UNICOS/mk and IRIX systems, infinity is approximately 10 .
-
- _j An optional integer argument that, if specified, is used as a
- count for skipping the first section of sequential random
- numbers. You can use this to create a complete sequence of
- random numbers while running on many PEs by breaking up the
- sequence into subsequences and using RRAANNSSEETT() to get each
- subsequence started in the correct location.
-
- The names of these intrinsics cannot be passed as arguments.
-
- TThhee RRAANNFF AAllggoorriitthhmm
- In Fortran on CRAY C90 systems, the random number generation algorithm
- uses the following two equations:
-
- * SS((_n++11)) == MM11**SS((_n)) mmoodd 22****4488
-
- * SS((_n++6644)) == MM6644**SS((_n)) mmoodd 22****4488
-
- Each SS((_i)) is the _ith seed.
-
- The first equation is used to generate the first 128 random numbers
- and store them in a table if a call to RRAANNSSEETT() was done. Otherwise,
- the table contains the first 128 random numbers from the default seed.
- The second equation is used because it vectorizes.
-
- The default seed is SS((00)) == 11227744332211447777441133115555 (octal).
-
- The operations MM11**SS((_n)) and MM6644**SS((_n)) are done as integer
- multiplications in such a way to preserve the lower 48 bits. It is
- the lower 48 bits that make the next random number seed and are used
- in the return value.
-
- The return value (random number) is the newly generated seed with an
- exponent of 40000 (octal) added. This is normalized before exit.
-
- The multiplier MM11 is 11220077226644227711773300556655 (octal) and is related to MM6644 by
- the following expression:
- MM6644 = lower 48 bits of MM11****6644 == 77002277442233334466112255440011 (octal).
-
- For example, the following Fortran program, when compiled with the
- ff9900 --ii 6644 option on a CRAY C90 system, is the equivalent of the RRAANNFF
- function:
-
- cc
- c THIS IS A FORTRAN VERSION OF RANF() FUNCTION
- cc
- REAL FUNCTION RANF()
- REAL NORM
- INTEGER MHI,MLO,EXPO,SEED,SEEDHI,SEEDLO
- DATA SEED/1274321477413155B/
- SAVE SEED
-
- MHI = 12072642B
- MLO = 71730565B
-
- EXPO = SHIFTL(40000B,48)
-
- SEEDHI = SHIFTR(AND(SHIFTL(77777777B,24),SEED),24)
- SEEDLO = AND(77777777B,SEED)
-
- SEED = AND(7777777777777777B,SEEDLO*MLO+
- 1 SHIFTL(SEEDLO*MHI+SEEDHI*MLO,24))
-
- RANF=NORM(OR(EXPO,SEED),0.0)
- RETURN
- END
- cc
- c THIS IS HERE TO NORMALIZE THE FLOATING POINT RESULT
- cc
- REAL FUNCTION NORM(X,Y)
- REAL X,Y
- NORM = X+Y
- RETURN
- END
-
- On IRIX systems, RRAANNFF uses a 64-bit linear congruential generator with
- a default seed of 1274321477413155 (octal).
-
- TThhee RRAANNFF RReeppeeaatt PPeerriioodd
- In Fortran, the period of RRAANNFF(()) is 2**46. If you need to insure that
- two random number ranges do not overlap, you can determine this
- empirically by generating the two sets of numbers and comparing them
- against one another, and also against themselves, for an overlap. It
- should be noted, however, that when using RRAANNSSEETT to set the random
- number seed, the algorithm used always rounds up even-numbered seeds
- to the nearest odd-numbered seed (that is, the right most bit is
- always set to one). Some adjacent pairs of seeds will generate
- exactly the same set of random numbers. For example, seeds 4 and 5
- will generate the same set of random numbers.
-
- RRAANNFF aanndd MMuullttiittaasskkiinngg
- In Fortran, the random number generator uses static memory storage for
- the random number seed table, so the RRAANNFF, RRAANNSSEETT, and RRAANNGGEETT
- functions must be protected (locked) when called from a multitasked
- program.
-
- RRAANNFF generates a set of random numbers such that each random number
- depends on the previous random number for its value. Thus, depending
- on the order in which the tasks calling RRAANNFF execute, a different set
- of random numbers will be returned to each task. It cannot be
- guaranteed that each task will get a distinct and reproducible set of
- random number values.
-
- RREETTUURRNN VVAALLUUEESS
- __rraannff and RRAANNFF return a 64-bit floating-point number in the range
- 0.0 < _x < 1.0.
-
- RRAANNGGEETT returns a 64-bit integer result.
-
- RRAANNSSEETT returns a 64-bit typeless result.
-
- EEXXAAMMPPLLEESS
- The following examples are written in Fortran:
-
- DO 10 I=1,10
- 10 RANDOM(I)=RANF()
-
-
- _i_s_e_e_d=RANGET(_i_v_a_l_u_e)
-
-
- _d_u_m_m_y=RANSET(_i_v_a_l_u_e)
-
- SSEEEE AALLSSOO
- RRAANNDDOOMM__NNUUMMBBEERR(3I), RRAANNDDOOMM__SSEEEEDD(3I)
-
- rraanndd(3C) in the _U_N_I_C_O_S _S_y_s_t_e_m _L_i_b_r_a_r_i_e_s _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l
-
- A complete list of C/C++ intrinsic functions available on UNICOS and
- UNICOS/mk systems is in the _C_r_a_y _C/_C++ _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l.
-
- _I_n_t_r_i_n_s_i_c _P_r_o_c_e_d_u_r_e_s _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l for the printed version of this
- man page.
-